package com.cn.jx;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.cn.jx.common.controller.BaseController;
import com.cn.jx.manager.po.SystemConfig;
import com.cn.jx.manager.service.mtn.IResourceServiceMtn;
import com.cn.jx.manager.service.query.IMessageServiceQry;
import com.cn.jx.manager.service.query.INoticeServiceQry;
import com.cn.jx.manager.service.query.IResourceServiceQry;
import com.jx.base.SessionUser;
import com.jx.enumType.ApplyEnum;
import com.jx.enumType.ResourceTypeEnum;
import com.jx.model.MenuEntry;
import com.jx.util.Constant;

/**
 * 
 * @author 姜旭
 * @version v1.11.20.2019
 * @since 
 * <p>创建时间：2019年12月1日
 * <p>功能描述：
 * <p>官方网站：management/admin/index
 * <p>邮箱地址：524577360@qq.com
 */
@Controller
public class AdminController  extends BaseController{

	@Autowired
	protected IResourceServiceQry resourceServiceQry;
	@Autowired
	protected IResourceServiceMtn resourceServiceMtn;
	@Autowired
	private INoticeServiceQry noticeServiceQry;
	@Autowired
	private IMessageServiceQry messageServiceQry;
	
	/**
	 * 
	* @Title: admin
	* @Description: TODO(后台首页)
	* <p>邮箱地址：524577360@qq.com
	* @param model
	* @param request
	* @return 
	* @return String    返回类型
	* @throws 
	 */
	@RequestMapping("/admin/index")
	public String admin(Model model, HttpServletRequest request) {
		SessionUser sessUser = getSessionUser(request);
		// 加入权限
		List<MenuEntry> result = resourceServiceQry.findResourceTree(ApplyEnum.ADMIN,Constant._ROOT, sessUser.getResourceCodeList());
		model.addAttribute("menuRoot", result);
		model.addAttribute("outlink", ResourceTypeEnum.OUT_LINK.getCode());
		model.addAttribute("curentapp", ApplyEnum.ADMIN.getCode());
		
		 /**获取系统配置信息 */
		SystemConfig config= systemInfoServiceQry.findSystemConfig();
    	model.addAttribute(Constant._SYSTEM_CONFIG, config);
		return "index";
	}
	 
	/**
	 * 
	* @Title: adminMain
	* @Description: TODO(首页)
	* <p>邮箱地址：524577360@qq.com
	* @param model
	* @return
	* @return String 返回类型
	* @throws
	 */
	@RequestMapping("/admin/main")
	 public String adminMain(Model model, HttpServletRequest request){
		
		SessionUser sessUser = getSessionUser(request);
		//最新的前5条通知
		model.addAttribute("noticelist", noticeServiceQry.findLatestFive());
		
		Long noRead=messageServiceQry.findInboxTodayCount(sessUser.getUserId());
		model.addAttribute("noReadEmail", noRead);
		
		model.addAttribute("emaillist", messageServiceQry.findLatelyReceiveMessage(sessUser.getUserId()));
		 return "main";
	 }
	 
	 /**
	  * 
	 * @Title: adminAbout
	 * @Description: TODO(跳转到关于本站声明页面)
	 * <p>邮箱地址：524577360@qq.com
	 * @throws 
	  */
	 @RequestMapping("about")
	 public String adminAbout(Model model){
		 return "about/adminAbout";
	 }
	 
	/**
	 * 
	* @Title: adminError
	* @Description: TODO(各种错误类型页面)
	* <p>邮箱地址：524577360@qq.com
	* @throws 
	 */
	 @RequestMapping("error/{path}")
	 public String adminError(Model model,@PathVariable("path") String path,String msg){
		 model.addAttribute("path", path);
		 model.addAttribute("msg", msg);
		 return "error/error";
	 }
	 
	/**
	 * 
	* @Title: adminErrorOverdue
	* @Description: TODO(跳转到过期页面)
	* <p>邮箱地址：524577360@qq.com
	* @throws 
	 */
	 @RequestMapping("error/overdue/")
	 public String adminErrorOverdue(Model model,String license){
		 model.addAttribute("license", license);
		 return "error/overdue";
	 }
	 
	 /**
	  * 
	 * @Title: adminNoPermissions
	 * @Description: TODO(跳转到无权限页面)
	 * <p>邮箱地址：524577360@qq.com
	 * @throws 
	  */
	 @RequestMapping("error/nopermissions/")
	 public String adminNoPermissions(Model model){
		 return "error/permissions";
	 }
	 
	 @RequestMapping("time")
	 public String dateTime(Model model){
		 return "about/adminAbout";
	 }
}
